home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PRINTER / JPSRC11.ARJ / JETFONT.H < prev    next >
C/C++ Source or Header  |  1991-08-03  |  8KB  |  231 lines

  1. /*
  2.  *      JET PAK - HP DeskJet and LaserJet series printer utilities
  3.  *
  4.  *      JETFONT header - soft font utility definitions
  5.  *
  6.  *      Version 1.1 (Public Domain)
  7.  */
  8.  
  9. /* Conversion between units */
  10. #define dots_to_points(d)         (((float)(d) * 6.0)/25.0)
  11. #define quarter_dots_to_points(d) (((float)(d) * 6.0)/100.0)
  12. #define quarter_dots_to_lpi(d)    ((d) == 0 ? 0.0 : (1200.0/(float)(d)))
  13.  
  14. /*
  15.  * FONT FILE DEFINITIONS
  16.  */
  17.  
  18. /* Field types */
  19. typedef unsigned char  BOOLEAN;
  20. typedef unsigned char  UNSIGNEDBYTE;
  21. typedef          char  SIGNEDBYTE;
  22. typedef unsigned short UNSIGNEDINT;
  23. typedef          short SIGNEDINT;
  24. typedef          char  ASC16[16];
  25.  
  26. /* Font descriptor structure (command_type == FDC) ... */
  27. #define COMMENT_SIZE_MAX 800
  28. typedef struct font_descriptor_struct
  29. {
  30.     UNSIGNEDINT  size;
  31.     UNSIGNEDBYTE header_format;
  32.     UNSIGNEDBYTE type;
  33.     UNSIGNEDINT  reserved1;
  34.     UNSIGNEDINT  baseline_distance;
  35.     UNSIGNEDINT  cell_width;
  36.     UNSIGNEDINT  cell_height;
  37.     UNSIGNEDBYTE orientation;
  38.     BOOLEAN spacing;
  39.     UNSIGNEDINT  symbol_set;
  40.     UNSIGNEDINT  pitch;
  41.     UNSIGNEDINT  height;
  42.     UNSIGNEDINT  x_height;
  43.     SIGNEDBYTE   width_type;
  44.     UNSIGNEDINT  style;
  45.     SIGNEDBYTE   stroke_weight;
  46.     UNSIGNEDINT  typeface;
  47.     UNSIGNEDBYTE slant;
  48.     UNSIGNEDBYTE serif_style;
  49.     UNSIGNEDBYTE quality;
  50.     SIGNEDBYTE   placement;
  51.     SIGNEDBYTE   underline_distance;
  52.     UNSIGNEDBYTE underline_height;
  53.     UNSIGNEDINT  text_height;
  54.     UNSIGNEDINT  text_width;
  55.     UNSIGNEDINT  first_code;
  56.     UNSIGNEDINT  last_code;
  57.     UNSIGNEDBYTE pitch_extended;
  58.     UNSIGNEDBYTE height_extended;
  59.     UNSIGNEDINT  reserved2;
  60.     UNSIGNEDINT  font_number_top;
  61.     UNSIGNEDINT  font_number_bot;
  62.     ASC16        name;
  63.     UNSIGNEDINT  h_pixel_resolution;
  64.     UNSIGNEDINT  v_pixel_resolution;
  65.     SIGNEDBYTE   tdu_distance;
  66.     UNSIGNEDBYTE tdu_height;
  67.     SIGNEDBYTE   bdu_distance;
  68.     UNSIGNEDBYTE bdu_height;
  69.     UNSIGNEDINT  specific_size;
  70.     UNSIGNEDINT  data_size;
  71.     BOOLEAN      unidirection;
  72.     BOOLEAN      compressed;
  73.     UNSIGNEDBYTE hold_time_factor;
  74.     BOOLEAN      no_half_pitch;
  75.     BOOLEAN      no_double_pitch;
  76.     BOOLEAN      no_half_height;
  77.     BOOLEAN      no_bold;
  78.     BOOLEAN      no_draft;
  79.     BOOLEAN      bold_method;
  80.     UNSIGNEDBYTE reserved3;
  81.     UNSIGNEDINT  baseline_offset_2;
  82.     UNSIGNEDINT  baseline_offset_3;
  83.     UNSIGNEDINT  baseline_offset_4;
  84.     ASC16        name_extension;
  85.     char         comment[COMMENT_SIZE_MAX];
  86. } FONT_DESCRIPTOR;
  87.  
  88.     /* ... and constants associated with various fields */
  89. #define LJFDSIZE            64  /* .size in LJ font file */
  90. #define DJFDSIZE            72  /* .size in DJ/DJ+ font files */
  91. #define DJ500FDSIZE         74  /* .size in DJ500 font file */
  92.  
  93. #define LJFONTFORMAT        0   /* .header_format in LJ font file */
  94. #define DJFONTFORMAT        5   /* .header_format in DJ font file */
  95. #define DJPFONTFORMAT       9   /* .header_format in DJ+ font file */
  96. #define DJ500FONTFORMAT     12  /* .header_format in DJ500 font file */
  97.  
  98. #define FONT_TYPE_7BIT      0   /* .type in a 7-bit font */
  99. #define FONT_TYPE_8BIT      1   /* .type in a 8-bit font */
  100. #define FONT_TYPE_IBM       2   /* .type in a IBM font */
  101.  
  102. #define FIXED               0   /* .spacing fixed */
  103. #define PROPORTIONAL        1   /* .spacing proportional */
  104.  
  105. #define PORTRAIT            0   /* .orientation portrait */
  106. #define LANDSCAPE           1   /* .orientation landscape */
  107.  
  108. #define LJSSIZE             0   /* .specific_size in LJ font file */
  109. #define DJSSIZE             20  /* .specific_size in DJ font file */
  110. #define DJ500SSIZE          36  /* .specific_size in DJ500 font file */
  111.  
  112. #define MULTI_PASS_OFFSET   48  /* approved dot offset between DJ passes */
  113.  
  114.     /* ... height of the individual pass bitmaps; the pass bitmaps
  115.            overlap by 2 bits, which in the top pass(es) should be clear */
  116. #define PASS_OVERLAP    2
  117. #define PASS_HEIGHT     (MULTI_PASS_OFFSET + PASS_OVERLAP)
  118.  
  119.     /* ... number of lines usable for data in each DJ pass */
  120. #define lines_for_pass(pass) (pass==0?PASS_HEIGHT:MULTI_PASS_OFFSET)
  121.  
  122.     /* ... largest design cell usable on the DeskJet series */
  123. #define MAX_CELL_HEIGHT (PASS_HEIGHT + MULTI_PASS_OFFSET*3)
  124. #define MAX_CELL_WIDTH  254
  125.  
  126.     /* ... range in which underlines may lie on DJ */
  127. #define UNDERLINE_MAX   PASS_HEIGHT
  128. #define UNDERLINE_MIN   (UNDERLINE_MAX-12)
  129.  
  130.     /* ... rule of thumb to calculate underline height */
  131. #define underline_height_for_height(h) (h/64)
  132.  
  133.     /* ... rule of thumb to calculate hold time factor */
  134. #define hold_time_factor_for_height(h) (h/3)
  135.  
  136. /* Character Descriptor structure (command_type == CDC) ... */
  137. #define BITMAP_SIZE_MAX 8000
  138. typedef struct character_descriptor_struct
  139. {
  140.     UNSIGNEDBYTE format;
  141.     BOOLEAN      continuation;
  142.     union character_descriptor_data {
  143.         struct ljchar_struct {
  144.             UNSIGNEDBYTE descriptor_size;
  145.             UNSIGNEDBYTE class;
  146.             UNSIGNEDBYTE orientation;
  147.             UNSIGNEDBYTE reserved;
  148.             SIGNEDINT    left_offset;
  149.             SIGNEDINT    top_offset;
  150.             UNSIGNEDINT  character_width;
  151.             UNSIGNEDINT  character_height;
  152.             SIGNEDINT    delta_x;
  153.             UNSIGNEDBYTE bitmap[BITMAP_SIZE_MAX];
  154.         } ljchar;
  155.  
  156.         struct djchar_struct {
  157.             UNSIGNEDBYTE descriptor_size;
  158.             UNSIGNEDBYTE char_type;
  159.             UNSIGNEDBYTE character_width;
  160.             UNSIGNEDBYTE comp_width;
  161.             SIGNEDBYTE   left_offset;
  162.             SIGNEDBYTE   right_offset;
  163.             UNSIGNEDBYTE bitmap[BITMAP_SIZE_MAX];
  164.         } djchar;
  165.     } data;
  166. } CHARACTER_DESCRIPTOR;
  167.  
  168.     /* ... and constants associated with various fields */
  169. #define LJCHARFORMAT        4   /* .format in LJ font file */
  170. #define DJCHARFORMAT        5   /* .format in DJ font file */
  171. #define DJPCHARFORMAT       9   /* .format in DJ+ font file */
  172. #define DJ500CHARFORMAT     12  /* .format in DJ500 font file */
  173.  
  174. #define LJCDSIZE            14  /* .descriptor_size in LJ font file */
  175. #define DJCDSIZE            6   /* .descriptor_size in DJ font file */
  176.  
  177. #define CHAR_TYPE_NORMAL    0   /* .char_type values in DJ font */
  178. #define CHAR_TYPE_PASS1     2
  179. #define CHAR_TYPE_PASS2     3
  180. #define CHAR_TYPE_PASS3     4
  181. #define CHAR_TYPE_PASS4     5
  182.  
  183.     /* macros to convert between char_type values and useful numbers */
  184. #define char_type_for_pass(pass) (pass + 2)
  185. #define pass_for_char_type(type) (type == CHAR_TYPE_NORMAL?type:type - 2)
  186.  
  187. /* Generic font command structure */
  188. typedef struct font_command_struct {
  189.     int command_type;
  190.     int number;
  191.     union font_command_data {
  192.         FONT_DESCRIPTOR      font;
  193.         CHARACTER_DESCRIPTOR character;
  194.     } data;
  195. } FONT_COMMAND;
  196.  
  197. /* Font command escape sequences */
  198. #define FDC     0           /* .command_type for font descriptor */
  199. #define FDC_S   ")s"        /* font descriptor command start */
  200. #define FDC_E   "W"         /* font descriptor command end */
  201.  
  202. #define CCC     (FDC+1)     /* .command_type for character code */
  203. #define CCC_S   "*c"        /* character code command start */
  204. #define CCC_E   "E"         /* character code command end */
  205.  
  206. #define CDC     (CCC+1)     /* .command_type for character descriptor */
  207. #define CDC_S   "(s"        /* character descriptor command start */
  208. #define CDC_E   "W"         /* character descriptor command end */
  209.  
  210. /*
  211.  * DEFINITIONS FOR DUMP FORMAT
  212.  */
  213.  
  214. #define COMMENT_CHARACTER   '#'
  215. #define KEYWORD_CHARACTER   '$'
  216.  
  217. #define KEYWORD_FILE        "$FILE"
  218. #define KEYWORD_HEADER      "$HEADER"
  219. #define KEYWORD_NAME        "$NAME"
  220. #define KEYWORD_COMMENT     "$COMMENT"
  221. #define KEYWORD_CHAR        "$CHAR"
  222. #define KEYWORD_BITMAP      "$BITMAP"
  223.  
  224. /*
  225.  * DECLARATIONS OF PUBLIC FUNCTIONS
  226.  */
  227.  
  228. /* Utility functions */
  229. extern int  font_command_read();
  230. extern int  font_command_write();
  231.